package com.baozun.houji.me.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.baozhun.mall.common.base.BaseActivity
import com.baozun.houji.me.R
import com.baozun.houji.me.databinding.ActivityCollectBinding
import com.baozun.houji.me.fragment.BrowseHistoryFragment
import com.baozun.houji.me.fragment.MyCollectionFragment
import com.baozun.houji.me.model.enums.CollectTabType
import com.baozun.houji.me.viewmodel.CollectionViewModel

/**
 * @Title：我的收藏activity
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/12
 * @Version：1.0.0
 */
class MyCollectionActivity : BaseActivity<CollectionViewModel, ActivityCollectBinding>() {

    private val mCollectTabType by lazy { intent.getIntExtra(COLLECT_TAB_TYPE, 0) }

    private val mTabFragmentList = arrayListOf<Fragment>(
        BrowseHistoryFragment.newInstance(),
        MyCollectionFragment.newInstance(),
    )

    companion object {
        private const val COLLECT_TAB_TYPE = "collectTabType"
        fun start(context: Context, collectTabType: CollectTabType) {
            var intent = Intent(context, MyCollectionActivity::class.java)
            intent.putExtra(COLLECT_TAB_TYPE, collectTabType.type)
            context.startActivity(intent)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        mDataBinding.tabLayout.setViewPager(
            mDataBinding.viewpager,
            arrayOf(CollectTabType.BROWSE.tabName, CollectTabType.COLLECT.tabName),
            this,
            mTabFragmentList
        )
        mDataBinding.viewpager.currentItem = mCollectTabType
    }


    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.iv_back -> {
                finish()
            }
        }
    }
}